<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
		<script type="text/javascript" src="../../scripts/menu/EditableItem.js"></script>
		<script type="text/javascript" src="../../scripts/menu/RangeMenu.js"></script>
		<script type="text/javascript" src="../../scripts/grid/GridFilters.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/Filter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js"></script>
        <script type="text/javascript">
            var fcMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.francecustomer');
            var store;
            var grid;
            
            var deleteCallback = function(btn){
                if (btn == 'yes') {
                    Ext.Ajax.request({
                        url: '../../servlet/SysMessageServlet?action=2&id=' + deleteId,
                        success: function(o){
                            if (o.responseText == 'success') {
                                store.reload();
                                messageTip.msg('Tip', 'Delete successfully.');
                            }
                            else {
                                messageTip.msg('Tip', 'Delete unsuccessfully.');
                            }
                        },
                        failure: function(o){
                            messageTip.msg('Tip', 'Delete failure.');
                        },
                        params: {
                            foo: 'bar'
                        }
                    });
                }
            }
			
			var filters = new Ext.grid.GridFilters({
					  filters:[
					    {type: 'string',  dataIndex: 'keyCode'},
						{type: 'string',  dataIndex: 'descriptionCn'},
						{type: 'string',  dataIndex: 'descriptionFr'},
						{type: 'string',  dataIndex: 'descriptionEn'}
			]});
            
            Ext.onReady(function(){
                // create the Data Store
                
                
                store = new Ext.data.Store({
                    // load using HTTP
                    url: '../../servlet/SysMessageServlet?action=4',
                    
                    // the return will be XML, so lets set up a reader
                    reader: new Ext.data.XmlReader({
                        // records will have an "Item" tag
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, [ // set up the fields mapping into the xml doc
                    // The first needs mapping, the others are very basic
                    'index', 'keyCode', 'descriptionCn', 'descriptionFr', 'descriptionEn', 'id', 'id']),
                    
                    remoteSort: true
                });
                
                store.setDefaultSort('keyCode', 'asc');
                
                // create the grid
                grid = new Ext.grid.GridPanel({
                    title: 'System Information Label List',
                    store: store,
                    height: 560,
					plugins: filters,
                    columns: [{
                        header: "ID",
                        width: 20,
                        dataIndex: 'index',
                        sortable: false
                    }, {
                        header: "KeyCode",
                        width: 80,
                        dataIndex: 'keyCode',
                        sortable: true
                    }, {
                        header: "DescriptionCn",
                        dataIndex: 'descriptionCn',
                        sortable: true
                    }, {
                        header: "DescriptionFr",
                        dataIndex: 'descriptionFr',
                        sortable: true
                    }, {
                        header: "DescriptionEn",
                        dataIndex: 'descriptionEn',
                        sortable: true
                    }, {
                        header: "Edit",
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderEdit
                    }, {
                        header: "Del",
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderDelete
                    }],
                    viewConfig: {
                        forceFit: true
                    },
                    loadMask: true,
                    renderTo: 'sysMessageGrid',
                    bbar: new Ext.PagingToolbar({
                        pageSize: 20,
                        store: store,
                        displayInfo: true
                    })
                });
                
                var startPage = getPrarmeterValue(window.location, 'startPage');
                var start;
                if (startPage == null || startPage == '') {
                    start = 0;
                }
                else {
                    start = (startPage - 1) * 20;
                }
                store.load({
                    params: {
                        start: start,
                        limit: 20
                    }
                });
                
                function renderEdit(value, p, record){
                    return String.format('<a href="system_label_edit.html?id={0}&startPage={1}" target="_self"><img src="../../images/icons/pencil.png" title="Edit" /></a>', record.id, Math.floor((record.data.index - 1) / 20) + 1);
                }
                
                function renderDelete(value, p, record){
                    return String.format('<a href="javascript: deleteItem(deleteCallback, {0});"><img src="../../images/icons/delete.png" title="Delete"/></a>', record.id);
                }
                
                var detailWin;
                grid.on('rowdblclick', function(grid, rowIndex, e){
                    if (!detailWin) {
                        detailWin = new Ext.Window({
                            title: 'Detail Window',
                            layout: 'fit',
                            width: 500,
                            height: 300,
                            closeAction: 'hide',
                            plain: true,
                            items: [{
                                id: 'detailPanel',
                                region: 'center',
                                bodyStyle: {
                                    background: '#ffffff',
                                    padding: '7px'
                                },
                                html: 'Please select a item to see the details.'
                            }]
                        });
                    }
                    
                    detailWin.show(this);
                    var itemTplMarkup = [
						'<table cellspacing="0" id="the-table"><tbody>',
							'<tr><td style="background:#eeeeee; width: 25%;">ID',
							'</td><td>{id}</td></tr>',
							'<tr><td style="background:#eeeeee;">Key Code',
							'</td><td>{keyCode}</td></tr>',
							'<tr><td style="background:#eeeeee;">Description CN',
							'</td><td>{descriptionCn}</td></tr>',
							'<tr><td style="background:#eeeeee;">Description FR',
							'</td><td>{descriptionFr}</td></tr>',
							'<tr><td style="background:#eeeeee;">Description EN',
							'</td><td>{descriptionEn}</td></tr>',
						'</tbody></table>'
					
					
					];
                    var itemTpl = new Ext.Template(itemTplMarkup);
                    var detailPanel = Ext.getCmp('detailPanel');
                    itemTpl.overwrite(detailPanel.body, grid.getStore().getAt(rowIndex).data);
                });
                
                
            });
        </script>
        <title></title>
    </head>
    <body>
        <div id="sysMessageGrid">
        </div>
    </body>
</html>
